package com.zhy.generator.config;
import com.zhy.generator.codegen.dom.xml.Attribute;
import com.zhy.generator.codegen.dom.xml.XmlElement;

import java.util.List;

import static cn.hutool.core.util.StrUtil.isNotBlank;
import static com.zhy.generator.codegen.util.Messages.getString;

public class IgnoredColumnException extends IgnoredColumn {

    public IgnoredColumnException(String columnName) {
        super(columnName);
    }

    @Override
    public XmlElement toXmlElement() {
        XmlElement xmlElement = new XmlElement("except"); //$NON-NLS-1$
        xmlElement.addAttribute(new Attribute("column", columnName)); //$NON-NLS-1$

        if (isNotBlank(configuredDelimitedColumnName)) {
            xmlElement.addAttribute(new Attribute(
                    "delimitedColumnName", configuredDelimitedColumnName)); //$NON-NLS-1$
        }

        return xmlElement;
    }

    @Override
    public void validate(List<String> errors, String tableName) {
        if (!isNotBlank(columnName)) {
            errors.add(getString("ValidationError.26", tableName));
        }
    }
}
